<template>
  <div ref="chartRef" style="height: 280px; text-align: center"></div>
</template>
<script lang="ts" setup>
  import { Ref, ref } from 'vue';
  import { useECharts } from '/@/hooks/web/useECharts';
  import { inventorylist } from '../api';
  const inventoryData = ref([]);
  const chartRef = ref<HTMLDivElement | null>(null);
  const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  // const loading = ref(true);
  (async () => {
    // 在组件挂载后调用 API
    try {
      const response = await inventorylist({}); // 调用 count API 方法
      // 处理成功响应
      // console.log(response, '响应数据');
      inventoryData.value = response.records;
      // console.log(inventoryData, '图表数据');
      console.log(inventoryData.value, '图表数据加value');
      setOptions({
        tooltip: {
          trigger: 'item',
        },
        //右边的示例
        legend: {
          orient: 'vertical',
          left: 'auto',
        },
        series: [
          {
            type: 'pie', // 将图表类型修改为饼图
            radius: '60%',
            center: ['50%', '50%'],
            data: inventoryData.value,
          },
        ],
      });
    } catch (error) {
      console.error(error);
    }
  })();
</script>

<style scoped></style>
